﻿package mortal.game.view.heroArena.util
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.utils.*;
    import extend.language.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.control.*;
    import mortal.game.manager.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.scene3D.map3D.AstarAnyDirection.data.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.view.arena.data.*;

    public class HeroArenaUtil extends Object
    {
        public static var isObserverModel:Boolean;

        public function HeroArenaUtil()
        {
            return;
        }// end function

        public static function isNewArea() : Boolean
        {
            var _loc_1:* = Cache.instance.login.loginGame.openDt;
            var _loc_2:* = ClockManager.instance.nowDate;
            var _loc_3:* = (_loc_2.time - _loc_1.time) / (1000 * 3600 * 24);
            if (_loc_3 <= 7)
            {
                return true;
            }
            return false;
        }// end function

        public static function getArenaDayRuleData() : Array
        {
            var _loc_4:int = 0;
            var _loc_5:TArenaConfig = null;
            var _loc_6:ArenaDayRuleData = null;
            var _loc_1:* = getArenaInitScore();
            var _loc_2:* = ArenaConfig.instance.getInfosByTypeAndLevel(ECopyType._ECopyTypeArena2v2, 5);
            var _loc_3:Array = [];
            for each (_loc_5 in _loc_2)
            {
                
                _loc_6 = new ArenaDayRuleData();
                _loc_6.pointMinValue = _loc_1 + _loc_5.condExtend;
                _loc_6.pointMaxValue = _loc_1 + _loc_5.val;
                _loc_6.rewardMaxValue = _loc_5.valExtend + (_loc_5.val - _loc_5.condExtend) * _loc_5.valExTend2 / 10000;
                if (_loc_5.val > 100000)
                {
                    _loc_4 = _loc_5.condExtend + 2000;
                }
                else
                {
                    _loc_4 = _loc_5.val;
                }
                _loc_6.rewardMinValue = _loc_5.valExtend + (_loc_5.condExtend - _loc_5.condExtend) * _loc_5.valExTend2 / 10000;
                _loc_3.push(_loc_6);
            }
            return _loc_3;
        }// end function

        public static function getArenaWeekRuleData(param1:int) : Array
        {
            var _loc_3:int = 0;
            var _loc_6:TArenaReward = null;
            var _loc_7:ArenaWeekRuleData = null;
            var _loc_2:* = HeroArenaController.HeroArenaLevel;
            if (param1 == EArenaRewardType._EArenaRewardTypeWeek)
            {
                _loc_3 = ArenaController.ArenaBTopLevel;
            }
            else
            {
                _loc_3 = ArenaController.ArenaZoneBTopLevel;
            }
            var _loc_4:* = ArenaRewardConfig.instance.getInfosByTypeAndLevel(param1, _loc_2, ECopyType._ECopyTypeArena2v2);
            var _loc_5:Array = [];
            for each (_loc_6 in _loc_4)
            {
                
                _loc_7 = new ArenaWeekRuleData();
                _loc_7.type = param1;
                _loc_7.rankMaxValue = _loc_6.rankCondMax;
                _loc_7.rankMinValue = _loc_6.rankCondMin;
                if (_loc_2 >= _loc_3)
                {
                    _loc_7.itemCode = _loc_6.diaoItemCode;
                }
                else
                {
                    _loc_7.itemCode = _loc_6.itemCode;
                }
                _loc_5.push(_loc_7);
            }
            return _loc_5;
        }// end function

        public static function getArenaInitScore() : int
        {
            var _loc_3:int = 0;
            var _loc_1:* = ArenaConfig.instance.getInfosByTypeAndLevel(ECopyType._ECopyTypeArena2v2, 2, HeroArenaController.HeroArenaLevel);
            var _loc_2:* = _loc_1[0] as TArenaConfig;
            if (_loc_2)
            {
                _loc_3 = _loc_2.val;
            }
            return _loc_3;
        }// end function

        public static function getStrCode(param1:int, param2:Boolean = true) : int
        {
            var _loc_3:int = 0;
            switch(param1)
            {
                case EEntityAttribute._EAttributeArena2Bronze:
                {
                    _loc_3 = param2 ? (40612) : (40613);
                    break;
                }
                case EEntityAttribute._EAttributeArena2Silver:
                {
                    _loc_3 = param2 ? (40614) : (40615);
                    break;
                }
                case EEntityAttribute._EAttributeArena2Gold:
                {
                    _loc_3 = param2 ? (40616) : (40617);
                    break;
                }
                case EEntityAttribute._EAttributeArena2Jewel:
                {
                    _loc_3 = param2 ? (40618) : (40619);
                    break;
                }
                case EEntityAttribute._EAttributeArena2SJewel:
                {
                    _loc_3 = param2 ? (40620) : (40621);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_3;
        }// end function

        public static function getArenaMoneyByLevel(param1:int) : ArenaMoney
        {
            var _loc_2:* = new ArenaMoney();
            if (param1 >= 0 && param1 < 70)
            {
                _loc_2.moneyName = Language.getString(41523);
                _loc_2.moneyNum = Cache.instance.role.money.arena2Bronze;
                _loc_2.shopIndex = 0;
            }
            else if (param1 >= 70 && param1 < 80)
            {
                _loc_2.moneyName = Language.getString(41524);
                _loc_2.moneyNum = Cache.instance.role.money.arena2Silver;
                _loc_2.shopIndex = 0;
            }
            else if (param1 >= 80 && param1 < 90)
            {
                _loc_2.moneyName = Language.getString(41525);
                _loc_2.moneyNum = Cache.instance.role.money.arena2Gold;
                _loc_2.shopIndex = 1;
            }
            else if (param1 >= 90 && param1 < 100)
            {
                _loc_2.moneyName = Language.getString(41526);
                _loc_2.moneyNum = Cache.instance.role.money.arena2Jewel;
                _loc_2.shopIndex = 2;
            }
            else
            {
                _loc_2.moneyName = Language.getString(41527);
                _loc_2.moneyNum = Cache.instance.role.money.arena2SJewel;
                _loc_2.shopIndex = 3;
            }
            _loc_2.itemCode = ArenaConfig.instance.getArenaMoneyCode(2, param1, ECopyType._ECopyTypeArena2v2);
            return _loc_2;
        }// end function

        public static function getVipAddition() : int
        {
            var _loc_3:int = 0;
            var _loc_1:* = Cache.instance.vip.level;
            var _loc_2:* = VipConfig.instance.getVipConfigByType(EVipRecordType._EVipRecordTypeArenaMoney);
            if (_loc_1 > 0 && _loc_2 != null)
            {
                _loc_3 = _loc_2["vip" + _loc_1] == null ? (0) : (int(_loc_2["vip" + _loc_1]));
            }
            return _loc_3;
        }// end function

        public static function isSelfTeamLeader(param1:SArena2v2Team = null) : Boolean
        {
            var _loc_2:* = Cache.instance.heroArena.myTeamInfo;
            var _loc_3:* = param1 == null ? (_loc_2) : (param1);
            if (_loc_3 && _loc_3.captainPlayer)
            {
                if (_loc_3.captainPlayer.name == Cache.instance.role.entityInfo.name)
                {
                    return true;
                }
            }
            return false;
        }// end function

        public static function isTeamFull(param1:SArena2v2Team = null) : Boolean
        {
            var _loc_2:* = Cache.instance.heroArena.myTeamInfo;
            var _loc_3:* = param1 == null ? (_loc_2) : (param1);
            if (_loc_3 && _loc_3.captainId.id != 0 && _loc_3.memberId.id != 0)
            {
                return true;
            }
            return false;
        }// end function

        public static function showTipOnTeamChange(param1:SArena2v2Team, param2:SArena2v2Team) : void
        {
            var _loc_4:String = null;
            var _loc_3:* = Cache.instance.role.entityInfo.name;
            if (param1 == null && param2 != null)
            {
                if (isSelfTeamLeader(param2))
                {
                    MsgManager.showRollTipsMsg(Language.getString(41528));
                }
                else
                {
                    _loc_4 = Language.getString(41529) + HTMLUtil.addColor(param2.name, GlobalStyle.colorHuang2);
                    MsgManager.showRollTipsMsg(_loc_4);
                }
            }
            else if (param1 != null && param2 == null)
            {
                if (isSelfTeamLeader(param1))
                {
                    MsgManager.showRollTipsMsg(Language.getString(41530));
                }
                else
                {
                    MsgManager.showRollTipsMsg(Language.getString(41531));
                }
            }
            else if (param1 && param2)
            {
                if (isSelfTeamLeader(param2))
                {
                    if (param1.memberId.id == 0 && param2.memberId.id != 0)
                    {
                        MsgManager.showRollTipsMsg(param2.memberPlayer.name + Language.getString(41532));
                    }
                    else if (param1.memberId.id != 0 && param2.memberId.id == 0)
                    {
                        MsgManager.showRollTipsMsg(Language.getString(41533));
                    }
                }
            }
            return;
        }// end function

        public static function isNearNpc(param1:int) : Boolean
        {
            var _loc_2:* = ThingUtil.npcUtil.getNpc(param1);
            if (_loc_2 != null)
            {
                if (GeomUtil.calcDistance(RolePlayer.instance.x2d, RolePlayer.instance.y2d, _loc_2.x2d, _loc_2.y2d) < GameConst.NpcInDistance + 40)
                {
                    return true;
                }
            }
            return false;
        }// end function

    }
}
